home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / MiniGameManager.as < prev    next >
Encoding:
Text File  |  2007-09-27  |  8.0 KB  |  264 lines

  1. class MiniGameManager extends Library.DispatcherBase
  2. {
  3.    var mcRef;
  4.    var aMoonStones;
  5.    var aMiniStones;
  6.    var nPosition;
  7.    var bScrollEnded;
  8.    var bCalledEnd;
  9.    var oWindSlow;
  10.    var oWindNormal;
  11.    var oWindFast;
  12.    var bPaused;
  13.    var oTak;
  14.    var mcBg1;
  15.    var mcBg2;
  16.    var mcGame;
  17.    var mcFront;
  18.    var nTargetPosition;
  19.    static var oCtrl;
  20.    static var TAK_FLY_START_X = 300;
  21.    static var TAK_FLY_START_Y = -50;
  22.    static var TAK_FOLLOW_Y = -150;
  23.    static var REMOVE_DEPTH = 1000000;
  24.    function MiniGameManager(__mcRef)
  25.    {
  26.       super();
  27.       this.mcRef = __mcRef;
  28.       MiniGameManager.oCtrl = this;
  29.       this.mcRef._y = Game.STAGE_HEIGHT;
  30.       this.aMoonStones = new Array();
  31.       this.aMiniStones = new Array();
  32.       this.nPosition = 0;
  33.       this.bScrollEnded = false;
  34.       this.bCalledEnd = false;
  35.       Main.Instance.doAddListener(this);
  36.       this.doBuildLevel();
  37.       this.doStartWindFast();
  38.    }
  39.    static function get Instance()
  40.    {
  41.       return MiniGameManager.oCtrl;
  42.    }
  43.    function doSoundEvent(__nEvent, __oSound)
  44.    {
  45.       if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
  46.       {
  47.          if(__oSound == this.oWindSlow)
  48.          {
  49.             delete this.oWindSlow;
  50.          }
  51.          else if(__oSound == this.oWindNormal)
  52.          {
  53.             delete this.oWindNormal;
  54.          }
  55.          else if(__oSound == this.oWindFast)
  56.          {
  57.             delete this.oWindFast;
  58.          }
  59.       }
  60.    }
  61.    function doStopWinds()
  62.    {
  63.       if(this.oWindSlow != undefined)
  64.       {
  65.          this.oWindSlow.doFadeTo(0);
  66.       }
  67.       if(this.oWindNormal != undefined)
  68.       {
  69.          this.oWindNormal.doFadeTo(0);
  70.       }
  71.       if(this.oWindFast != undefined)
  72.       {
  73.          this.oWindFast.doFadeTo(0);
  74.       }
  75.    }
  76.    function doStartWindSlow()
  77.    {
  78.       if(this.oWindSlow == undefined)
  79.       {
  80.          Library.Sound.SoundManager.isSoundPlaying("Wind_Slow.wav").oSound.doStop();
  81.          this.oWindSlow = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Wind_Slow.wav",0,999);
  82.          this.oWindSlow.doAddListener(this);
  83.          this.oWindSlow.setFadeRate(3);
  84.       }
  85.       this.oWindSlow.doFadeTo(100);
  86.       if(this.oWindNormal != undefined)
  87.       {
  88.          this.oWindNormal.doFadeTo(0);
  89.       }
  90.       if(this.oWindFast != undefined)
  91.       {
  92.          this.oWindFast.doFadeTo(0);
  93.       }
  94.    }
  95.    function doStartWindNormal()
  96.    {
  97.       if(this.oWindNormal == undefined)
  98.       {
  99.          Library.Sound.SoundManager.isSoundPlaying("Wind_Normal.wav").oSound.doStop();
  100.          this.oWindNormal = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Wind_Normal.wav",0,999);
  101.          this.oWindNormal.doAddListener(this);
  102.          this.oWindNormal.setFadeRate(3);
  103.       }
  104.       this.oWindNormal.doFadeTo(100);
  105.       if(this.oWindSlow != undefined)
  106.       {
  107.          this.oWindSlow.doFadeTo(0);
  108.       }
  109.       if(this.oWindFast != undefined)
  110.       {
  111.          this.oWindFast.doFadeTo(0);
  112.       }
  113.    }
  114.    function doStartWindFast()
  115.    {
  116.       if(this.oWindFast == undefined)
  117.       {
  118.          Library.Sound.SoundManager.isSoundPlaying("Wind_Fast.wav").oSound.doStop();
  119.          this.oWindFast = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Wind_Fast.wav",100,999);
  120.          this.oWindFast.doAddListener(this);
  121.          this.oWindFast.setFadeRate(3);
  122.       }
  123.       this.oWindFast.doFadeTo(100);
  124.       if(this.oWindNormal != undefined)
  125.       {
  126.          this.oWindNormal.doFadeTo(0);
  127.       }
  128.       if(this.oWindSlow != undefined)
  129.       {
  130.          this.oWindSlow.doFadeTo(0);
  131.       }
  132.    }
  133.    function doMinigameEnd()
  134.    {
  135.       if(!this.bCalledEnd)
  136.       {
  137.          this.bCalledEnd = true;
  138.          this.doStopWinds();
  139.          Game.Instance.doMinigameEnd();
  140.       }
  141.    }
  142.    function doAddMiniStone(__mcObject)
  143.    {
  144.       var _loc2_ = new MiniStoneSky(__mcObject);
  145.       this.aMiniStones.push(_loc2_);
  146.    }
  147.    function doAddMoonStone(__mcObject)
  148.    {
  149.       var _loc2_ = new MoonStoneSky(__mcObject);
  150.       this.aMoonStones.push(_loc2_);
  151.    }
  152.    function doEnterFrame()
  153.    {
  154.       super.doEnterFrame();
  155.       if(!this.bPaused)
  156.       {
  157.          this.doScroll();
  158.          this.doCheckMoonstones();
  159.          this.doCheckMinistones();
  160.       }
  161.    }
  162.    function doDestroy()
  163.    {
  164.       super.doDestroy();
  165.       this.oWindFast.doStop();
  166.       this.oWindSlow.doStop();
  167.       this.oWindNormal.doStop();
  168.       delete this.oWindFast;
  169.       delete this.oWindSlow;
  170.       delete this.oWindNormal;
  171.       this.oTak.doDestroy();
  172.       delete this.oTak;
  173.       delete MiniGameManager.oCtrl;
  174.       Main.Instance.doRemoveListener(this);
  175.       this.mcBg1.removeMovieClip();
  176.       this.mcBg2.removeMovieClip();
  177.       this.mcGame.removeMovieClip();
  178.       this.mcFront.removeMovieClip();
  179.    }
  180.    function doCheckMoonstones()
  181.    {
  182.       for(var _loc3_ in this.aMoonStones)
  183.       {
  184.          var _loc2_ = Library.Utils.MoreMath.getDistance(this.aMoonStones[_loc3_].Ref._x + this.aMoonStones[_loc3_].Ref._parent._x,this.aMoonStones[_loc3_].Ref._y + this.aMoonStones[_loc3_].Ref._parent._y,this.oTak.Ref._x,this.oTak.Ref._y);
  185.          if(_loc2_ < 75)
  186.          {
  187.             this.aMoonStones[_loc3_].onCatched();
  188.             Game.Instance.onCatchMoonstone();
  189.             this.aMoonStones.splice(Number(_loc3_),1);
  190.          }
  191.       }
  192.    }
  193.    function doCheckMinistones()
  194.    {
  195.       for(var _loc3_ in this.aMiniStones)
  196.       {
  197.          var _loc2_ = Library.Utils.MoreMath.getDistance(this.aMiniStones[_loc3_].Ref._x + this.aMiniStones[_loc3_].Ref._parent._x,this.aMiniStones[_loc3_].Ref._y + this.aMiniStones[_loc3_].Ref._parent._y,this.oTak.Ref._x,this.oTak.Ref._y);
  198.          if(_loc2_ < 75)
  199.          {
  200.             this.aMiniStones[_loc3_].onCatched();
  201.             Game.Instance.onCatchMiniStone();
  202.             this.aMiniStones.splice(Number(_loc3_),1);
  203.          }
  204.       }
  205.    }
  206.    function doScroll()
  207.    {
  208.       if(!this.bScrollEnded)
  209.       {
  210.          var _loc2_ = this.nPosition;
  211.          this.nTargetPosition = - (this.oTak.Ref._y - this.oTak.FollowY);
  212.          if(this.nTargetPosition < 0)
  213.          {
  214.             this.nTargetPosition = 0;
  215.             this.nPosition = 0;
  216.             this.bScrollEnded = true;
  217.          }
  218.          else
  219.          {
  220.             this.nPosition += (this.nTargetPosition - this.nPosition) / 2;
  221.          }
  222.          this.mcBg1._y = this.nPosition * 0.2;
  223.          this.mcBg2._y = this.nPosition * 0.5;
  224.          this.mcGame._y = this.nPosition;
  225.          this.mcFront._y = this.nPosition * 1.1;
  226.       }
  227.    }
  228.    function doBuildLevel()
  229.    {
  230.       this.mcBg1 = this.mcRef.createEmptyMovieClip("mcBg1",1);
  231.       var _loc2_ = this.mcBg1.attachMovie("Panel_SkyBg","mcBg1_1",1);
  232.       _loc2_._y = - this.mcBg1._height;
  233.       this.mcBg2 = this.mcRef.createEmptyMovieClip("mcBg2",2);
  234.       var _loc3_ = 1;
  235.       while(_loc3_ <= 5)
  236.       {
  237.          _loc2_ = this.mcBg2.attachMovie("Panel_SkyBg2","mcBg2_" + _loc3_,_loc3_);
  238.          _loc2_._y = - _loc2_._height * _loc3_;
  239.          _loc3_ = _loc3_ + 1;
  240.       }
  241.       this.mcGame = this.mcRef.createEmptyMovieClip("mcGame",3);
  242.       _loc3_ = 1;
  243.       while(_loc3_ <= 4)
  244.       {
  245.          var _loc4_ = "Panel_SkyGame" + Library.Utils.MoreMath.getRandomRange(1,3);
  246.          _loc2_ = this.mcGame.attachMovie(_loc4_,"mcGame_" + _loc3_,_loc3_);
  247.          _loc2_._y = - _loc2_._height * _loc3_;
  248.          _loc3_ = _loc3_ + 1;
  249.       }
  250.       this.mcFront = this.mcRef.createEmptyMovieClip("mcFront",4);
  251.       _loc3_ = 1;
  252.       while(_loc3_ <= 14)
  253.       {
  254.          _loc2_ = this.mcBg2.attachMovie("Panel_SkyFront","mcFront_" + _loc3_,_loc3_);
  255.          _loc2_._y = - _loc2_._height * (_loc3_ * 0.99);
  256.          _loc3_ = _loc3_ + 1;
  257.       }
  258.       var _loc5_ = this.mcGame.attachMovie("Dynamic_TakFlying","mcTak",500);
  259.       _loc5_._x = MiniGameManager.TAK_FLY_START_X;
  260.       _loc5_._y = MiniGameManager.TAK_FLY_START_Y;
  261.       this.oTak = new TakFlying(_loc5_);
  262.    }
  263. }
  264.